import request from "@/utils/request"

// 附件上传
export function uploadFile(data) {
  return request({
    url: `/upload`,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data
  })
}
// ---------------------------应用管理----------------------------
// 新增应用
export function addAppManager(data) {
  return request({
    url: `/sysAppManager`,
    method: "post",
    data
  })
}

// 查询应用管理列表
export function appManagerList(data, { currentPage, size }) {
  return request({
    url: `/sysAppManager/search/${currentPage}/${size}`,
    method: "post",
    data
  })
}

// 查询应用管理详情
export function appManagerInfo(appManagerId) {
  return request({
    url: `/sysAppManager/` + appManagerId,
    method: "get",
  })
}

// 修改应用
export function updateAppManager(data) {
  return request({
    url: `/sysAppManager`,
    method: "put",
    data
  })
}

// 删除应用
export function appManagerDel(appManagerId) {
  return request({
    url: `/sysAppManager/` + appManagerId,
    method: "delete",
  })
}

// 查询密钥
export function getSecret(appManagerId) {
  return request({
    url: `/sysAppManager/selectSecret/` + appManagerId,
    method: "get",
  })
}

// 重置密钥
export function resetSecretApi(appManagerId) {
  return request({
    url: `/sysAppManager/resetSecret/` + appManagerId,
    method: "put",
  })
}

// ---------------------------应用分类----------------------------

// 新增分类
export function addAppType(data) {
  return request({
    url: `/sysAppType`,
    method: "post",
    data
  })
}

//-----------------------------应用权限----------------------

// 查询分类树形
export function appTypeTree() {
  return request({
    url: `/sysAppType/findTree`,
    method: "post",
  })
}

// 查询已绑定应用权限
export function appSelectedTypeTree(roleId) {
  return request({
    url: `/sysRoleAppType/findList`,
    method: "post",
    data: {roleId},
  })
}

// 应用权限绑定
export function appBinding(roleId, appTypeIds) {
  return request({
    url: `/sysRoleAppType`,
    method: "post",
    data: {roleId, appTypeIds},
  })
}


// 查询分类详情
export function appTypeInfo(appTypeId) {
  return request({
    url: `/sysAppType/` + appTypeId,
    method: "get",
  })
}

// 修改分类
export function updateAppType(data) {
  return request({
    url: `/sysAppType`,
    method: "put",
    data
  })
}

// 删除分类
export function appTypeDel(appTypeId) {
  return request({
    url: `/sysAppType/` + appTypeId,
    method: "delete",
  })
}

// 绑定应用
export function bindAppManager(data) {
  return request({
    url: `/sysAppType/bindAppManager`,
    method: "put",
    data
  })
}

// 取消绑定
export function cancleAppManagerApi(data) {
  return request({
    url: `/sysAppType/cancleAppManager`,
    method: "put",
    data
  })
}

// 获取登录凭证
export function getLoginTicket() {
  return request({
    url: `/thiredLogin/consumer/sendTicket`,
    method: "get",
    headers: {
      isToken: false,
    },
  })
}

// 根据ticket和token获取重定向地址
export function getRedirectUrl(ticket, token) {
  return request({
    url: import.meta.env.VITE_REDIRECT_BASE_URL + '/thiredLogin/provider/getRedirectUrl',
    method: "post",
    headers: {
      Authorization: 'Bearer ' + token,
    },
    data: {ticket}
  })
}

// 获取验证码
export function getVerifyCodeImg() {
  return request({
    url: import.meta.env.VITE_REDIRECT_BASE_URL + "/imgCaptcha",
    method: "get",
    timeout: 20000,
  });
}

// 密码登录
export function login(data) {
  return request({
    url: import.meta.env.VITE_REDIRECT_BASE_URL + "/accountLogin",
    method: "post",
    data: data,
  });
}

// 手机号短信登录
export function phoneLogin(data) {
  return request({
    url: import.meta.env.VITE_REDIRECT_BASE_URL + "/phoneLogin",
    method: "post",
    data: data,
  });
}

// 登录发送短信
export function phoneCaptcha(userName) {
  return request({
    url: import.meta.env.VITE_REDIRECT_BASE_URL + `/phoneCaptcha/${userName}`,
    method: "get",
  });
}

// 找回密码发送短信
export function byPhone(userName) {
  return request({
    url: import.meta.env.VITE_REDIRECT_BASE_URL + `/forgetPassword/byPhone/${userName}`,
    method: "get",
  });
}
// 找回密码发送邮箱
export function byMail(email) {
  return request({
    url: import.meta.env.VITE_REDIRECT_BASE_URL + `/forgetPassword/byMail/${email}`,
    method: "get",
  });
}

// 校验验证码
export function checkPhone(data) {
  return request({
    url: import.meta.env.VITE_REDIRECT_BASE_URL + `/forgetPassword/checkPhone`,
    method: "post",
    data
  });
}

// 校验邮箱验证码
export function checkMail(data) {
  return request({
    url: import.meta.env.VITE_REDIRECT_BASE_URL + `/forgetPassword/checkMail`,
    method: "post",
    data
  });
}

// 找回密码发送短信
export function resetPwdByForgetPassword(data) {
  return request({
    url: import.meta.env.VITE_REDIRECT_BASE_URL + `/sysUser/resetPwdByForgetPassword`,
    method: "put",
    data
  });
}

